package org.example.tools;


import dev.langchain4j.agent.tool.Tool;
import lombok.extern.slf4j.Slf4j;
import org.example.comment.feign.OrderFeign;
import org.example.comment.feign.ProductFeign;
import org.example.comment.feign.UserFeign;
import org.example.comment.utils.ThreadLocalUtil;
import org.example.entity.Order;
import org.example.result.Result;
import org.example.vo.ProductVo;
import org.example.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 数学工具类
 */
@Slf4j
@Component
public class AiChatAgentTools {

    @Autowired
    private OrderFeign orderFeign;

    @Autowired
    private ProductFeign productFeign;

    @Autowired
    private UserFeign userFeign;



    @Tool(name = "sum",value = "计算两个数的和")
    double sum(double a, double b) {
        log.info("调用加法运算");
        return a + b;
    }
    @Tool(name = "squareRoot",value = "计算平方根")
    double squareRoot(double x) {
        log.info("调用平方根运算");
        return Math.sqrt(x);
    }


    /**
     * 获取当前登录用户的所有订单
     * @return
     */
    @Tool(name = "getUserOrder",value = "获取当前登录用户的所有订单,如果订单中没有指定地址信息创建时间，请从向量存储中找到一个时间和地址信息")
    Result<List<Order>> getUserOrder() {
        log.info("调用获取当前登录用户所有订单");
        Long userId = (Long) ThreadLocalUtil.get();
        Result<List<Order>> orderByUserId = orderFeign.getOrderByUserId(userId);
        return orderByUserId;
    }


    /**
     * 获取所有商品信息
     * @return
     */
    @Tool(name = "getAllProduct",value = "获取所有商品信息，并进行智能推荐")
    Result<List<ProductVo>> getAllProduct() {
        log.info("调用获取所有商品信息");
        Result<List<ProductVo>> allProducts = productFeign.getAllProduct();
        return allProducts;
    }


    /**
     * 获取当前登录用户信息
     * @return
     */
    @Tool(name = "getUserInfo",value = "获取当前登录用户的信息，查看个人信息")
    Result<UserInfoVo> getUserInfo(){
        log.info("调用获取用户信息");
        Result<UserInfoVo> userInfo = userFeign.getUserInfo();
        return userInfo;
    }


    /**
     * 修改当前用户的手机号
     * @param phone
     * @return
     */
    @Tool(name = "updateUserPhone",value = "修改当前用户的手机号，修改后查询个人信息，并展示给用户")
    Result<String> updateUserPhone(String phone){
        log.info("调用修改用户手机号");
        userFeign.updateUserPhone(phone);
        return Result.success("修改成功");
    }

}
